package truef.commo.web.spring.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;

import edu.zut.cs.software.base.web.spring.controller.GenericController;
import edu.zut.cs.software.base.web.spring.controller.GenericController.TableList;
import truef.commodity.domain.Commodity;
import truef.service.commodity.service.CommodityManager;

@Controller
//拦截含有favorite的url并处理
@CrossOrigin(origins = "*")
@RequestMapping("/commodity") // 7.
public class CommodityController extends GenericController<Commodity, Long, CommodityManager> {
	CommodityManager commodityManager;

	/*
	 * 部署成功后，在浏览器中输入url http://localhost:8080/universalStore-web/${1.}/${2.value值}
	 * 例子:http://localhost:8080/universalStore-web/favorite/index.html
	 */
	@ResponseBody
	@RequestMapping(value = "/findall.json",produces = "application/json")
	public String findall() {
		List<Commodity> favoriteList = commodityManager.findAll();
		Gson gson = new Gson();
		String s = gson.toJson(favoriteList);
		return s;
	}

	@RequestMapping("/index")
    public String index() {
        return "admin/index";
    }
	@Autowired
	public void setUserManager(CommodityManager commodityManager) {
		this.commodityManager = commodityManager;
		this.manager = this.commodityManager;
	}
	

}
